package com.li.springbootproject.service.rabbitmq;

import com.li.springbootproject.config.rabbitmq.RabbitMqConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 8/12/2022 8:42 AM
 */
@Component
public class RabbitMqDequeOneConsume {

    private static final Logger logger = LoggerFactory.getLogger(RabbitMqDequeOneConsume.class);

    /**
     * 基础注解，指定queue的名称，可以多个。如果是simple不需要交换机的直接写队列名称就好。
     * 如果是其他的也想只指定一个queues——name的话，需要上面的配置类配置queue或者其他绑定关系
     * direct(默认模式)：发送方把消息发送给订阅方，如果有多个订阅者，默认采取轮询的方式进行消息发送
     *
     * @param message message
     */
    @RabbitListener(queues = RabbitMqConst.DEQUE_ONE)
    @RabbitHandler
    public void dequeOneConsumeOne(String message) {
        logger.info("dequeOne consume one received message: " + message);
    }

    @RabbitListener(queues = RabbitMqConst.DEQUE_ONE)
    @RabbitHandler
    public void dequeOneConsumeTwo(String message) {
        logger.info("dequeOne consume two received message: " + message);
    }

}
